<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/instance_not_found_exception.php");

require_once("lib/model/action.php");

require_once("model/autorfacade/to/statics_autor_to.php");

require_once("model/article/dao/article_dao_factory.php");
require_once("model/article_category/dao/article_category_dao_factory.php");
require_once("model/article_description/dao/article_description_dao_factory.php");
require_once("model/article_image/dao/article_image_dao_factory.php");
require_once("model/article_video/dao/article_video_dao_factory.php");
require_once("model/article_comment/dao/article_comment_dao_factory.php");
require_once("model/article_link/dao/article_link_dao_factory.php");

class Get_statics_user_action implements Action {

	private $login;
	
	public function __construct($login) {
		
		$this->login = $login;
	}
	
	public function do_execute() {
		try {
			$dao = Article_dao_factory::singleton()->get_dao();
			$articles = $dao->count_articles_by_login($this->login);
			
			$dao = Article_category_dao_factory::singleton()->get_dao();
			$categories = $dao->count_categories_by_login($this->login);
			
			$dao = Article_description_dao_factory::singleton()->get_dao();
			$descriptions = $dao->count_descriptions_by_login($this->login);
			
			$dao = Article_image_dao_factory::singleton()->get_dao();
			$images = $dao->count_images_by_login($this->login);
			
			$dao = Article_video_dao_factory::singleton()->get_dao();
			$videos = $dao->count_videos_by_login($this->login);
			
			$dao = Article_comment_dao_factory::singleton()->get_dao();
			$comments = $dao->count_comments_by_login($this->login);
			
			$dao = Article_link_dao_factory::singleton()->get_dao();
			$links = $dao->count_links_by_login($this->login);
			
			return new Statics_autor_to($articles, $categories, $descriptions, 
											$images, $videos, $comments, $links);
		}
		catch (Instance_not_found_exception $e) {
			throw new Model_exception($e);
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}
?>